/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ValueNode.h"

ValueNode::ValueNode(Real value)
        :_value(value) {
}
/**
 *\fn ExpressionTreeNode* ValueNode::copy() const
 *\brief Returns a deep copy of the tree having as root the current node
 * Reimplemented in derived classes
 *
 */
ExpressionTreeNode* ValueNode::copy() const{
    return new ValueNode(_value);
}

/**
 *\fn Real ValueNode::eval() const
 *\brief Recursively evaluates contained math expression
 * Reimplemented in derived classes
 *
 */
Real ValueNode::eval() const{
    return _value;
}
/**
 *\fn SmartPtr<ExpressionTreeNode> ValueNode::derive(const QString& varName) const
 *\brief Returns the tree associated to the symbolic math derivative of the contained math expression
 *\param varName Name of the variable with respect to which the derivative is computed
 * Reimplemented in derived classes
 */
SmartPtr<ExpressionTreeNode> ValueNode::derive(const QString&) const{
    return new ValueNode(0.0);
}

/**
 *\fn SmartPtr<ExpressionTreeNode> ValueNode::firstLevelSimplification()() const
 *\brief
 * Reimplemented in derived classes
 */
SmartPtr<ExpressionTreeNode> ValueNode::firstLevelSimplification() const {
    return copy();
}

/**
 *\fn QString ValueNode::info() const
 *\brief Returns the information contained by the node
 * That could be the symbol of the operand, the variable name or the value as a string
 * Reimplemented in derived classes
 */
QString ValueNode::info() const {
    return _value.toString();
}

QString ValueNode::toPrefixString() const {
    return info();
}

QString ValueNode::toPostfixString() const {
    return info();
}

QString ValueNode::toInfixString() const {
    return info();
}
/**
 *\fn EpressionTreeNode* ValueNode::replace(const QString& varName, ExpressionTreeNode* tree) const
 *\brief
 *
 */
ExpressionTreeNode* ValueNode::replace(const QString& /*varName*/, ExpressionTreeNode* /*tree*/) const {
    return copy();
}

/**
 *\fn EpressionTreeNode* ValueNode::replace(int varPos, ExpressionTreeNode* tree) const
 *\brief
 *
 */
ExpressionTreeNode* ValueNode::replace(int /*varPos*/, ExpressionTreeNode* /*tree*/) const {
    return copy();
}
